<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<script type="text/javascript">
	function statusFormatter(rowObject) {
		var p = 0, html = "", title = "";
		if (rowObject.priority_name != null) {

			switch (rowObject.priority_name) {
			case "一级":
				p = 1;
				break;
			case "二级":
				p = 2;
				break;
			case "三级":
				p = 3;
				break;
			case "四级":
				p = 4;
				break;
			case "五级":
				p = 5;
				break;
			}
			title = "优先级：" + p + "级";
		} else {
			title = "未确定优先级";
		}

		html = "<img title='"+title+"' src='img/incident/p"+p+".png'>";
		if (rowObject.sla_status == 1) {

			html = html + "&nbsp;<img title='SLA：异常'  src='img/incident/sla_unusual.png'>";
		}
		return html + "&nbsp;<a id='msg_" + rowObject.id + "' href=\"javascript:openRelationMessage('" + rowObject.id + "')\" class=''></a>";
	}
</script>
<div class="m m7" style="margin-bottom:10px;top:5px;">
	<div class="mc" style="padding:5px;">
		<table class="search-table" id="incidentSearchGridAdSearchTb">
			<tr>
				<td class="td1">编号：</td>
				<td class="td2"><input type="text" field="code" op="cn">
				</td>
				<td class="td1">关键字：</td>
				<td class="td2"><input type="text" field="title,description"
					op="cn"></td>
				<td class="td1">事件分类：</td>
				<td class="td2"><input type="hidden" id="icdCategoryId"
					field="category_name_path" op="cn" /> <isperp:treeSelector
						url="incident/category/getTree" id="icdCategorySelector"
						name="text" displayValue="" valueColumn="text"
						afterSelected="changeCategory(ids,names,treeNode)"
						valueControlId="icdCategoryId"></isperp:treeSelector></td>
			</tr>
			<tr>
				<td class="td1">登记时间：</td>
				<td class="td2"><input id="registerDateStart" type="date"
					field="create_date" op="gt" style="width: 68px" />~<input
					id="registerDateEnd" type="date" field="create_date" op="lt"
					style="width: 68px" /></td>
				<%-- <td class="td1">所属项目：</td>
				<td class="td2"><form:select path="projects" field="project_id"
						op="cn" data-allow-empty="true" items="${projects}" 
						itemLabel="name" itemValue="id" cssClass="search" />
				</td> --%>
				<td class="td1">是否关闭：</td>
				<td class="td2" colspan="3"><input type="radio" field="status"
					id="rs1" op="cn" name="gstatus" value="" checked="checked" /><label
					for="rs1">全部</label><input type="radio" field="status" op="eq"
					name="gstatus" value="已关闭" id="rs2" /><label for="rs2">已关闭</label><input
					type="radio" field="status" op="ne" name="gstatus" value="已关闭"
					id="rs3" /><label for="rs3">未关闭</label></td>
			</tr>
			<tr id="trIfShowExColumns1" style="display:none">
				<td class="td1">扩展列：</td>
				<td class="td2">
					<!-- <input type="radio"
					name="ifShowExtend" value="1" id="ifShowExtend1" /><label
					for="ifShowExtend1">是</label><input type="radio"
					name="ifShowExtend" value="0" checked="checked" id="ifShowExtend2" /><label
					for="ifShowExtend2">否</label> --> <a href="javascript:void(0)"
					onclick="setShowExtendColumns()" class="nui-txt-link">设置显示列</a>
				</td>
			</tr>
			<tr id="trIfShowExColumns2" style="display:none">
				<td class="td1">第一组：</td>
				<td colspan="5"><select class="search" data-width="130px"
					id="selectF1"
					onchange="changeExSelectFiled(this,'selectO1','selectV1')">

				</select> <select data-width="80px" id="selectO1">
						<option value="eq">=</option>
						<option value="cn">包含</option>

				</select> <span style="vertical-align: middle;"><input id="selectV1"
						field="jszc03p" op="cn" type="text"> </span></td>

			</tr>
			<tr id="trIfShowExColumns3" style="display:none">
				<td class="td1">第二组：</td>
				<td colspan="5"><select class="search" data-width="130px"
					id="selectF2"
					onchange="changeExSelectFiled(this,'selectO2','selectV2')">

				</select> <select id="ciProperty1Filter" data-width="80px" id="selectO2">
						<option value="eq">=</option>
						<option value="cn">包含</option>

				</select> <span id="ciProperty3Value" style="vertical-align: middle;"><input
						field="jszc03p" op="cn" id="selectV2" type="text"> </span></td>
			</tr>
			<tr id="trIfShowExColumns4" style="display:none">
				<td class="td1">第三组：</td>
				<td colspan="5"><select class="search" data-width="130px"
					id="selectF3"
					onchange="changeExSelectFiled(this,'selectO3','selectV3')">

				</select> <select id="ciProperty1Filter" data-width="80px" id="selectO3">
						<option value="eq">=</option>
						<option value="cn">包含</option>

				</select> <span id="ciProperty3Value" style="vertical-align: middle;"><input
						field="jszc03p" op="cn" id="selectV3" type="text"> </span></td>
			</tr>
		</table>

	</div>
</div>

<isperp:grid url="" adSearchTb="incidentSearchGridAdSearchTb"
	gridId="incidentSearchGrid" sortname="create_date" sortorder="desc"
	rowNum="10" loadComplete="isperp.loadMessageCount(data);"
	autoload="false" cusViewUrl="incident/incident/view"
	cusDeleteUrl="incident/incident/delete" editOrDeleteRightControl="true"
	showSearchbar="false"
	ondbClickRowEvent="incidentSearchGrid.view(rowid);" height="auto"
	excelExportUrl="incident/incident/excelExport">

	<jsp:attribute name="toolbar">
	<isperp:toolbar id="userToolbar">
	   <isperp:button id="categoryCiExport" icon="icon-download"
				text="导出到Excel"
				onclick="getSearchConditionAndSearch();incidentSearchGrid.excelExport();"></isperp:button>
	  <isperp:button id="categoryCreate" icon="icon-search" text="查询"
				onclick="getSearchConditionAndSearch();"></isperp:button>
	  <isperp:button id="categoryCreate" icon="icon-search" text="清空"
				onclick="clearSearchFilter();"></isperp:button>
	</isperp:toolbar>
	</jsp:attribute>

	<jsp:attribute name="searchbar">
	
	</jsp:attribute>
	<jsp:body>
	<isperp:column name="id" title="" hidden="true">
	</isperp:column>
	<isperp:column name="sla_status" title="" hidden="true"></isperp:column>
	<isperp:column name="priority_name" title="" width="40"
			isFormatterFun="true" formatter="return statusFormatter(rowObject);">
	</isperp:column>	

	<isperp:column name="code" title="编号" width="134" showInHead="true"
			fixed="true">
	</isperp:column>
	<isperp:column name="ci_code" title="资产编号" showInHead="false"
			width="80"></isperp:column>
	<isperp:column name="incident_type" showInHead="false" title="性质"
			width="60"></isperp:column>
 
	
	<isperp:column name="happen_time" title="发生时间" showInHead="false"
			width="80">
	</isperp:column>
	
	
	<isperp:column name="title" title="标题" width="150" showInHead="true">
	</isperp:column>
	<isperp:column name="icd_category_name" title="事件分类" width="100"
			showInHead="true">
	</isperp:column>
	<%-- <isperp:column name="cus_department_name" title="请求人部门" width="70"
			showInHead="true">
	</isperp:column> --%>
	<isperp:column name="cus_user_name" title="请求人" showInHead="true"
			width="65">
	</isperp:column>
	
	<isperp:column name="project_name" title="所属项目" showInHead="true"
			width="80">
	</isperp:column>
	
	<isperp:column name="create_date" showInHead="true" title="创建时间"
			width="120">
	</isperp:column>
 
	<isperp:column name="assign_date" title="分派时间" showInHead="false"
			width="80">
	</isperp:column>
 
	<isperp:column name="source" showInHead="false" title="来源" width="60"></isperp:column>
 
	<isperp:column name="assigner_name" title="受理人" width="65"
			showInHead="false">
	</isperp:column>
	<isperp:column name="supporter_name" title="工程师" width="65"
			showInHead="false">
	</isperp:column> 
	<isperp:column name="status" title="状态" width="95" showInHead="true">
	</isperp:column>
	  
	<isperp:column name="solver_submit_time" title="工程师关单时间" width="120"
			showInHead="false">
	</isperp:column>
	<isperp:column name="solved_date" title="解决时间" width="110"
			showInHead="false">
	</isperp:column>
    <isperp:column name="description" title="描述" showInHead="false"
			width="80">
	</isperp:column>
	<isperp:column name="faultlocation_name" title="故障定位"
			showInHead="false" width="80">
	</isperp:column>
	<isperp:column name="reason_analyze" title="原因分析" showInHead="false"
			width="80">
	</isperp:column>
	<isperp:column name="solution" title="解决方案" showInHead="false"
			width="80">
	</isperp:column>
	<isperp:column name="handle_process" title="处理过程" showInHead="false"
			width="80">
	</isperp:column>
	<isperp:column name="deadline" title="最终期限" showInHead="false"
			width="80">
	</isperp:column>
	
	<isperp:column name="response_date" title="工程师接单时间" showInHead="false"
			width="80">
	</isperp:column>
    
	<isperp:column name="linkman_name" title="联系人" showInHead="false"
			width="60">
	</isperp:column>
	<isperp:column name="linkman_phone" title="联系人电话" showInHead="false"
			width="60">
	</isperp:column>
	
	<isperp:column name="urgency_name" title="紧急度" showInHead="false"
			width="50">
	</isperp:column>
	<isperp:column name="effect_name" title="影响度" showInHead="false"
			width="50">
	</isperp:column>
 

	<isperp:column name="solution_way" title="解决方式" showInHead="false"
			width="80">
	</isperp:column>
	<isperp:column name="solution_stage" title="解决阶段" showInHead="false"
			width="80">
	</isperp:column>
 
	<isperp:column name="satisfaction" title="满意度" showInHead="false"
			width="80">
	</isperp:column>
 
	<isperp:column name="are_feedback" title="是否客户评价" showInHead="false"
			width="50">
	</isperp:column>
	<isperp:column name="customer_opinion" title="客户意见" showInHead="false"
			width="80">
	</isperp:column>	
	<isperp:column name="closed_date" title="关闭时间" showInHead="false"
			width="80">
	</isperp:column>
	<isperp:column name="closer_name" title="关闭者" showInHead="false"
			width="80">
	</isperp:column>
	<isperp:column name="close_code" title="关闭码" showInHead="false"
			width="50">
	</isperp:column>
	</jsp:body>

</isperp:grid>

<div id="dialogSetColumnsDiv" title="选择扩展列" style="display: none;">
	<ul id="incidentSearchGridExColumns" class="jqgrid-colmuns ui-sortable"></ul>
</div>
<input type="text" id="newIncidentSearchGridColumnModelId"
	style="display:none">
<input type="text" id="newIncidentSearchGridColumnModelName"
	style="display:none">
<%-- <isperp:operate code="INC_SEARCH"></isperp:operate> --%>

<script type="text/javascript">
	function clearSearchFilter() {
		$("#incidentSearchGridAdSearchTb input[type='text'],#incidentSearchGridAdSearchTb select" + ",#incidentSearchGridAdSearchTb input[type='hidden']").each(function() {
			var $el = $(this);
			$el.val("");
			try {
				$el.trigger("chosen:updated");
			} catch (e) {
			}
		});
	}

	//基础列
	var baseSearchGridColModel = null;
	var baseSearchGridColNames = null;
	$(function() {
		baseSearchGridColModel = incidentSearchGrid.jqGrid.getGridParam("colModel");
		baseSearchGridColNames = incidentSearchGrid.jqGrid.getGridParam("colNames");

		getSearchConditionAndSearch();
	});

	$("#dialogSetColumnsDiv").dialog({
		autoOpen : false,
		resizable : false,
		modal : true,
		width : 440,
		height : 600,
		buttons : [ {
			text : "选择全部列",
			"class" : "nui-mainbtn",
			click : function() {
				$("#incidentSearchGridExColumns input").each(function() {
					$(this).get(0).checked = true;
				});
			}
		}, {
			text : "取消选择",
			"class" : "nui-mainbtn",
			click : function() {
				$("#incidentSearchGridExColumns input").each(function() {
					$(this).get(0).checked = false;
				});
			}
		}, {
			text : "确定",
			"class" : "nui-mainbtn",
			click : function() {
				var t_id = "", t_name = "";
				$("#incidentSearchGridExColumns input:checked").each(function() {
					var obj = $(this);
					var tid = obj.data("id");
					var tname = obj.data("name");
					t_id = t_id + tid + ",";
					t_name = t_name + tname + ",";
				});
				$("#newIncidentSearchGridColumnModelId").val(t_id.substring(0, t_id.length - 1));
				$("#newIncidentSearchGridColumnModelName").val(t_name.substring(0, t_name.length - 1));
				$(this).dialog("close");
				getSearchConditionAndSearch();
			}
		}, {
			text : "关闭",
			click : function() {
				$(this).dialog("close");
			}

		} ]
	});

	function changeExSelectFiled(obj, opid, vid) {
		//$("#"+vid).attr("field",$(obj).val());
		//$("#"+vid).attr("op",$("#"+opid).val());
	}

	function setShowExtendColumns() {

		$("#dialogSetColumnsDiv").dialog("open");

	}

	var categoryId = "";
	function changeCategory(ids, names, treeNode) {
		categoryId = treeNode.id;
		if (1==2) {
			$("[id^='trIfShowExColumns']").show();
			//根据事件分类获取 所有扩展属性列
			$.getJSON("incident/category/property/listByCategory?categoryId=" + categoryId, function(data) {
				var liStr = "";
				$("#incidentSearchGridExColumns").empty();
				$("#selectF1").empty();
				$("#selectF2").empty();
				$("#selectF3").empty();
				var tfOptionStr = "<option value=''></option>";
				$(data).each(function(index, item) {
					if (item.data_type != "list") {
						liStr += "<li class='ui-jqgrid-cc ui-sortable-handle'><input type='checkbox' id='gcc_"+item.id+"' data-id='"+item.id+"' data-name='"+item.name+"'/><label for='gcc_"+item.id+"'>" + item.name + "</label></li>";
						tfOptionStr += "<option value='"+item.id+"'>" + item.name + "</option>";
					}
					
				});
				$("#incidentSearchGridExColumns").append(liStr);
				$("#selectF1").append(tfOptionStr);
				$("#selectF2").append(tfOptionStr);
				$("#selectF3").append(tfOptionStr);
				$("#selectF1").trigger("chosen:updated");
				$("#selectF2").trigger("chosen:updated");
				$("#selectF3").trigger("chosen:updated");

			});
		}

	}
	function getSearchConditionAndSearch() {
		var ifShowExtend = 0;
		if ($("#newIncidentSearchGridColumnModelId").val() != "" || ($("#selectV1").val() != "" || $("#selectV2").val() != "" || $("#selectV3").val() != ""))
			ifShowExtend = 1;
		var tulr = "incident/search/list?ifShowExtend=" + ifShowExtend + "&categoryId=" + categoryId;
		incidentSearchGrid.jqGrid.setGridParam({
			url : tulr
		});
		if (categoryId) {
			var newincidentSearchGridColNames = baseSearchGridColNames.slice(1, baseSearchGridColNames.length - 1);
			var newincidentSearchGridColModel = baseSearchGridColModel.slice(1, baseSearchGridColModel.length - 1);

			if ($("#newIncidentSearchGridColumnModelId").val() != "") {
				var ids = $("#newIncidentSearchGridColumnModelId").val().split(",");
				var names = $("#newIncidentSearchGridColumnModelName").val().split(",");
				for ( var i = 0; i < ids.length; i++) {
					newincidentSearchGridColNames.push(names[i]);
					newincidentSearchGridColModel.push({
						label : names[i],
						name : ids[i],
						width : '80'
					});
				}

			}
			incidentSearchGrid.jqGrid.GridUnload();
			incidentSearchGrid.jqGrid = incidentSearchGrid.createGrid(newincidentSearchGridColNames, newincidentSearchGridColModel);
			incidentSearchGrid.jqGrid.setGridParam({
				url : tulr
			});
			reSetExtendColumnFilter();
			incidentSearchGrid.search();
		} else {
			incidentSearchGrid.search();
		}

	};

	function reSetExtendColumnFilter() {
		if ($("#selectF1").val() != "" && $("#selectV1").val() != "") {
			$("#selectV1").attr("field", $("#selectF1").val()).attr("op", $("#selectO1").val());
		}
		if ($("#selectF2").val() != "" && $("#selectV2").val() != "") {
			$("#selectV2").attr("field", $("#selectF2").val()).attr("op", $("#selectO2").val());
		}
		if ($("#selectF3").val() != "" && $("#selectV3").val() != "") {
			$("#selectV3").attr("field", $("#selectF3").val()).attr("op", $("#selectO3").val());
		}
	}

	function getSearchCondition(treeNodeId) {
		var newincidentSearchGridColNames = incidentSearchGridColNames.slice(1, incidentSearchGridColNames.length - 2);
		var newincidentSearchGridColModel = incidentSearchGridColModel.slice(1, incidentSearchGridColModel.length - 2);
		var f = "customerId=" + $("#customerId").val();
		if (customerCiCategoryMenu1.getSelectedNode()) {
			if (treeNodeId == null || treeNodeId == undefined) {
				var tn = customerCiCategoryMenu1.getSelectedNode();
				f += "&categoryId=" + tn.id + "&categoryNamePath=" + tn.treenodeNamePath;
			}
		}
		resetColumn = false;
		$("#ciProperty1,#ciProperty2,#ciProperty3,#ciProperty4,#ciProperty5,#ciProperty6").each(function(index, item) {
			var o = $(item).find("option:selected");
			var oVal = $(o).val();
			if (oVal) {
				var iId = $(item).attr("id");
				var oValue = $("#" + iId + "ValueControl").val();
				if (oValue) {
					var iIndex = index + 1;
					f += "&p" + iIndex + "=" + oVal + "&p" + iIndex + "op=" + $("#" + iId + "Filter").val() + "&p" + iIndex + "value=" + encodeURIComponent(oValue);
					newincidentSearchGridColNames.push($(o).text());
					newincidentSearchGridColModel.push({
						label : $(o).text(),
						name : "p" + iIndex,
						width : '80'
					});
					resetColumn = true;
				}
			}
		});
		newincidentSearchGridColNames.push("描述");
		newincidentSearchGridColModel.push({
			label : '描述',
			name : "description",
			width : '80'
		});
		incidentSearchGrid.jqGrid.GridUnload();
		incidentSearchGrid.jqGrid = incidentSearchGrid.createGrid(newincidentSearchGridColNames, newincidentSearchGridColModel);
		return f;
	}

	function openRelationMessage(id) {

		isperp.openDialog({
			title : "查看消息",
			contentUrl : "app/message/relationMessageView?all=1&sourceId=" + id
		});
	}
</script>